var app = {
	//	ip: 'weixin.jlstjzx.com',
	//	port: '80',
	ip: '192.168.0.174',
	port: '80',
	ctx: '',
	publicKey: 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJJYdeUb7SyG82V1Pn/mFNWUtuR/1ewjK9be4zfmlsX0Xhc2hnx+A+vtVZBzWotylINCPOPf448yz2KmwVRYTUkCAwEAAQ=='
};
app.baseUrl = 'http://' + app.ip + ':' + app.port + app.ctx;
app.setUser = function(user) {
	user = user || {};
	localStorage.setItem('$user', JSON.stringify(user));
};
app.getUser = function() {
	var json = localStorage.getItem('$user');
	if(json) {
		return JSON.parse(json);
	} else {
		return null;
	}
};
app.removeUser = function() {
	localStorage.removeItem('$user');
};
app.login = function(user, callback) {
	callback = callback || mui.noop;
	app.ajax(app.baseUrl + '/app/login', user, function(data) {
		if(data.success) {
			user.id = data.info.id;
			user.oid = data.info.oid;
			user.organ = data.info.organ;
			user.name = data.info.name;
			callback(user);
		} else {
			callback();
		}
	});
};
app.ajax = function(url, data, callback) {
	url = url || '';
	data = data || {};
	callback = callback || mui.noop;
	mui.ajax(url, {
		data: data,
		dataType: 'json',
		type: 'post',
		timeout: 5000,
		success: function(data) {
			callback(data);
		},
		error: function(xhr, type, errorThrown) {
			if(type == 'abort') {
				mui.toast('请连接网络');
				return;
			}
			if(type == 'timeout') {
				mui.toast('无法访问服务器');
				return;
			}
			if(type == 'error') {
				mui.toast('服务不存在');
				return;
			}
			alert(type);
		}
	});
};
Array.prototype.contains = function(needle) {
	for(i in this) {
		if(this[i] == needle) return true;
	}
	return false;
}